package com.briup.estore.dao.impl;

import com.briup.estore.common.pojo.Collect;
import com.briup.estore.common.utils.JDBCUtils;
import com.briup.estore.dao.CollectDao;

import java.util.List;

/**
 * @Author briup-adam
 * @Date 2023/8/3 下午3:01
 * @Description 对表【es_collect】的数据库操作
 **/

public class CollectDaoImpl implements CollectDao {
    @Override
    public List<Collect> findByUserId(Integer userId) {
        List<Collect> list = JDBCUtils.findMany("select id,user_id,book_id from es_collect where user_id=?;", Collect.class, userId);
        return list;
    }

    @Override
    public void save(Integer userId, Integer bookId) {
        JDBCUtils.DML("insert into es_collect(user_id,book_id) values(?,?)", userId, bookId);

    }

    @Override
    public void deleteById(Integer id) {
        JDBCUtils.DML(" delete from es_collect where id=?", id);
    }

    @Override
    public Collect findByUserIdAndBookId(int userId, int bookId) {
        Collect collect = JDBCUtils.findOne("select id,user_id,book_id from es_collect where user_id=? and book_id=?", Collect.class, userId, bookId);
        return  collect;
    }
}
